/**
 * used html5 web worker to launch independent javascript thread.
 * The main purpose of worker is used to looping rhythm.
 */
var workerTimerID=null;
var workerInterval=100;
self.onmessage=function(e){
	if (e.data.command=="start") {
		console.log("starting");
		workerTimerID=setInterval(function(){postMessage("schedule");},workerInterval);
	}
	else if (e.data.command=="interval") {
		console.log("setting interval");
		workerInterval=e.data.interval;
		console.log("interval="+workerInterval);
		if (workerTimerID) {
			clearInterval(workerTimerID);
			workerTimerID=setInterval(function(){postMessage("schedule");}, workerInterval);
		}
	}
	else if (e.data.command=="stop") {
		console.log("stopping");
		clearInterval(workerTimerID);
		workerTimerID=null;
	}
};